package com.redijedi.tapestry5.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import com.redijedi.tapestry5.TreeModel;
import com.redijedi.tapestry5.TreeNodeModel;

/**
 * @author torr
 * 
 */
public class TreeModelImpl implements TreeModel {

	private final Collection<TreeNodeModel> _nodes;

	private final Map<String, String> _attributes;

	public TreeModelImpl(Collection<TreeNodeModel> nodes,
			String... attributeKeysAndValues) {
		this(nodes, attributeKeysAndValues.length == 0 ? null : InternalUtils
				.mapFromKeysAndValues(attributeKeysAndValues));
	}

	public TreeModelImpl(Collection<TreeNodeModel> nodes,
			Map<String, String> attributes) {
		if (nodes == null) {
			_nodes = new ArrayList<TreeNodeModel>();
		} else {
			_nodes = nodes;
		}
		_attributes = attributes;
	}

	public Map<String, String> getAttributes() {
		return _attributes;
	}

	public Collection<TreeNodeModel> getNodes() {
		return _nodes;
	}

	public int getDepth() {
		return 0;
	}

	@Override
	public String toString() {
		return "TreeModel";
	}
}
